package command.gew;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import model.Questionario;

import command.ICommand;

import dao.QuestionarioDAO;

public class CriarQuestionarioCommand implements ICommand{

	@Override
	public String execute(HttpServletRequest request) throws ServletException,IOException {
		HttpSession session = request.getSession();
		@SuppressWarnings("unchecked")
		ArrayList<Integer> emocoes = (ArrayList<Integer>) session.getAttribute("emocoes");
		@SuppressWarnings("unchecked")
		ArrayList<Integer> respondentes = (ArrayList<Integer>) session.getAttribute("respondentes");
		Questionario questionario = new Questionario();
		questionario.setEmocoes(emocoes);
		questionario.setRespondentes(respondentes);
		QuestionarioDAO dao = new QuestionarioDAO();
		try {
			dao.inserir(questionario);
			return "/paginas/tela_principal.jsp";
		} catch (SQLException e) {
			e.printStackTrace();
			return "#";
		}
		
	}

}
